<?php  $pharmacy_id = $_SESSION['acc_id'];       
       $owner_id = $pharmacy_id;
       //echo $owner_id;
       
?> 
<link rel="stylesheet" href="css/jquery.ui.all.css">
<script src="js/jquery-1.8.0.js"></script>
<script src="js/jquery.ui.core.js"></script>
<script src="js/jquery.ui.widget.js"></script>
<script src="js/jquery.ui.datepicker.js"></script>
<link rel="stylesheet" href="css/demos.css">
<script>
    $(function() {
        $( "#datepicker" ).datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'yy-mm-dd' 
        });
		
        $( ".datepicker" ).datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'yy-mm-dd' 
        });
    });
</script>
<?php
if (!defined('W_ROOT')) {
    exit();
}
?>
<?php
if ($_GET['id']) {
    $ids = $_GET['id'];
    $_SESSION['id_for'] = $ids;
}
$selete_edit = "SELECT p.*, pro.* FROM tblpharmacy AS phar,tblproduct AS p, promotion AS pro WHERE phar.user_id = p.owner AND pro.product_id = p.id AND p.owner = $owner_id AND promotion_id='" . $ids . "'";
$run_query = mysql_query($selete_edit);
$num_rows = mysql_num_rows($run_query);
if ($num_rows > 0) {
    while (($rows = mysql_fetch_array($run_query, MYSQL_ASSOC))) {
        $product_id = $rows['product_id'];
        $sel_product = $rows['product_name'];
        $quantity = $rows['quantity'];
        $promotion = $rows['promotion'];
        $dateStock = $rows['date_in_stock'];
       
    }
}
?>
<div class="row-fluid">
    <div class="box">
        <form action="process.php?action=edit_promo"  method="post" name="frmlist" onSubmit="return validatePromotion()" enctype="multipart/form-data">
            <div class="title">Edit Promotion</div>
            <div class="row-fluid">	
                <div class="span4 offset8">
                    <input class="btn" type="submit" name="btnsave" value="Save"/>&nbsp;&nbsp;&nbsp;
                    <input class="btn" type="reset" name="btnreset" value="Reset" />&nbsp;&nbsp;&nbsp;
                    <input class="btn" type="button" name="btncancel" value="Cancel" onClick="javascript:window.history.back();" />
                </div>
            </div>
            <h3>Promotion Information</h3>
            <table cellpadding="5" cellspacing="5" border="0" width="100%" align="center">
                
                <tr>
                    <td colspan="3" align="left"><strong style="color:#F00;">* <?php echo $lang['ARE_REQUIR']; ?></strong></td>
                </tr>

                <tr> 
                    <td width="10%" height="30" align="left" valign="top"><?php echo $lang['PRO_NAME']; ?></td>
                    <td width="5%" align="left" valign="top">:</td>
                    <td width="80%" align="left">

                        <?php
                        $p_get = mysql_query("SELECT p.* FROM tblproduct AS p, tblpharmacy AS phar WHERE phar.user_id = p.owner AND p.owner = $owner_id");
                        ?>
                        <select name="selectProduct" id="selectbox" value="<?php echo $sel_product; ?>">
<!--                            <option>Select Promotion<?php //echo $lang['SEL_PRO']; ?></option>-->
                            <?php
                            while ($product = mysql_fetch_assoc($p_get)) {
                                ?>
                            <option value="<?php echo $product['id']; ?>" <?php echo($product['id']==$product_id)?' selected="selected"':''?>><?php echo $product['product_name']; ?></option>
                                <?php
                            }
                            ?>                           
                        </select>                       
                    </td>
                </tr>

                <tr> 
                    <td width="10%" height="30" align="left" valign="top"><?php echo $lang['QUANTITY']; ?></td>
                    <td width="5%" align="left" valign="top">:</td>
                    <td width="80%" align="left">
                        <input name="txtQuantity" type="text" placeholder="<?php echo $lang['QUANTITY']; ?>" alt="required" id="quantit"  value="<?php echo $quantity; ?>"  />&nbsp;&nbsp;<strong style="color:#F00;">*</strong>
                    </td>
                </tr>

                <tr> 
                    <td width="10%" height="30" align="left" valign="top"><?php echo $lang['%PROMOTION']; ?></td>
                    <td width="5%" align="left" valign="top">:</td>
                    <td width="80%" align="left">
                        <input name="txtPromotion" type="text" placeholder="<?php echo $lang['%PROMOTION']; ?>" alt="required" id="promot"  value="<?php echo $promotion; ?>"  />&nbsp;&nbsp;<strong style="color:#F00;">*</strong>
                    </td>
                </tr>

                <tr> 
                    <td width="10%" height="30" align="left" valign="top"><?php echo $lang['DATE_STOCK']; ?></td>
                    <td width="5%" align="left" valign="top">:</td>
                    <td width="80%" align="left">
                        <input name="txtDateStock" type="text" placeholder="<?php echo $lang['DATE_STOCK']; ?>"  id="datepicker" value="<?php echo $dateStock; ?>"  />&nbsp;&nbsp;<strong style="color:#F00;">*</strong>
                    </td>
                </tr>

                <tr>
                    <td style="background-color: white">&nbsp;&nbsp</td>
                </tr>
             
                
            </table>
        </form>
    </div><!--<div class="box">-->
</div><!--<div class="row-fluid">-->
<script type="text/javascript" language="javascript">
    function validatePromotion(){
        var quantity=document.forms["frmlist"]["txtQuantity"].value;
        var promotion=document.forms["frmlist"]["txtPromotion"].value;
        var dateStock=document.forms["frmlist"]["txtDateStock"].value;       
        
        if (quantity==null || quantity=="") {
            alert(" Quantity must be filled out");
            return false;
        }
        if (promotion==null || promotion=="") {
            alert(" %promotion must be filled out");
            return false;
        }
        if (dateStock==null || dateStock=="") {
            alert(" Date_in_Stock must be filled out");
            return false;
        }
						  
        					  
    }
</script>

